package com.minimoment.web.interceptor;

import com.annotation.LoginCheck;
import com.minimoment.model.domain.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.lang.reflect.Method;

/**
 * Created by etund on 2014/10/31.
 */
public class LoginInceptor extends AbstractInterceptor implements ModelDriven<User>{
    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
//        代理对象方法
        String methodName = actionInvocation.getProxy().getMethod();
//        获取当前的对象
        Class clazz = actionInvocation.getClass();
//        获取跟代理对象方法一样的当前对象的方法
        Method currentMethod = clazz.getMethod(methodName);
//        如果当前方法有目标注解
        if(currentMethod.isAnnotationPresent(LoginCheck.class)){
//            获取注解的值
            LoginCheck loginCheck = currentMethod.getAnnotation(LoginCheck.class);
            String value = loginCheck.value();
            if(value.equals("check")){

            }
        }
        return null;
    }

    @Override
    public User getModel() {
        return null;
    }
}
